﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using GameLayer;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using GameBase;
using GameInstrument;
using Microsoft.Xna.Framework.Design;
using MainGame;

namespace GameCharacter
{
    public class RedArcher : MyCharacter
    {
        public RedArcher(ContentManager content)
            : base(content)
        {
            String path = "Images/Sprites/RedArcher/";

            //Hit
            Sprite downHit = new Sprite(content, path + "DownHit/DownHit_", 13);
            Sprite dowLeftHit = new Sprite(content, path + "DownLeftHit/DownLeftHit_", 13);
            Sprite downRightHit = new Sprite(content, path + "DownRightHit/DownRightHit_", 13);

            Sprite leftHit = new Sprite(content, path + "LeftHit/LeftHit_", 13);
            Sprite rightHit = new Sprite(content, path + "RightHit/RightHit_", 13);

            Sprite upHit = new Sprite(content, path + "UpHit/UpHit_", 13);
            Sprite upLeftHit = new Sprite(content, path + "UpLeftHit/UpLeftHit_", 14);

            Sprite upRightHit = new Sprite(content, path + "UpRightHit/UpRightHit_", 16);
            //Go
            Sprite goDown = new Sprite(content, path + "GoDown/GoDown_", 8);
            Sprite goDownLeft = new Sprite(content, path + "GoDownLeft/GoDownLeft_", 8);
            Sprite goDownRight = new Sprite(content, path + "GoDownRight/GoDownRight_", 8);

            Sprite goLeft = new Sprite(content, path + "GoLeft/GoLeft_", 8);
            Sprite goRight = new Sprite(content, path + "GoRight/GoRight_", 6);

            Sprite goUp = new Sprite(content, path + "GoUp/GoUp_", 8);
            Sprite goUpLeft = new Sprite(content, path + "GoUpLeft/GoUpLeft_", 8);
            Sprite goUpRight = new Sprite(content, path + "GoUpRight/GoUpRight_", 8);
            //Die
            Sprite dieFromDown = new Sprite(content, path + "DieFromDown/DieFromDown_", 13);
            Sprite dieFromDownLeft = new Sprite(content, path + "DieFromDownLeft/DieFromDownLeft_", 14);
            Sprite dieFromDownRight = new Sprite(content, path + "DieFromDownRight/DieFromDownRight_", 13);

            Sprite dieFromLeft = new Sprite(content, path + "DieFromLeft/DieFromLeft_", 13);
            Sprite dieFromRight = new Sprite(content, path + "DieFromRight/DieFromRight_", 13);

            Sprite dieFromUp = new Sprite(content, path + "DieFromUp/DieFromUp_", 12);
            Sprite dieFromUpLeft = new Sprite(content, path + "DieFromUpLeft/DieFromUpLeft_", 13);
            Sprite dieFromUpRight = new Sprite(content, path + "DieFromUpRight/DieFromUpRight_", 13);

            /*----------------------------*/
            this.Items.Insert(DOWN_HIT, downHit);
            this.Items.Insert(DOWNLEFT_HIT, dowLeftHit);
            this.Items.Insert(DOWNRIGHT_HIT, downRightHit);

            this.Items.Insert(LEFT_HIT, leftHit);
            this.Items.Insert(RIGHT_HIT, rightHit);

            this.Items.Insert(UP_HIT, upHit);
            this.Items.Insert(UPLEFT_HIT, upLeftHit);
            this.Items.Insert(UPRIGHT_HIT, upRightHit);

            this.Items.Insert(GO_DOWN, goDown);
            this.Items.Insert(GO_DOWNLEFT, goDownLeft);
            this.Items.Insert(GO_DOWNRIGHT, goDownRight);

            this.Items.Insert(GO_LEFT, goLeft);
            this.Items.Insert(GO_RIGHT, goRight);

            this.Items.Insert(GO_UP, goUp);
            this.Items.Insert(GO_UPLEFT, goUpLeft);
            this.Items.Insert(GO_UPRIGHT, goUpRight);

            this.Items.Insert(DIE_FROMDOWN, dieFromDown);
            this.Items.Insert(DIE_FROMDOWNLEFT, dieFromDownLeft);
            this.Items.Insert(DIE_FROMDOWNRIGHT, dieFromDownRight);

            this.Items.Insert(DIE_FROMLEFT, dieFromLeft);
            this.Items.Insert(DIE_FROMRIGHT, dieFromRight);

            this.Items.Insert(DIE_FROMUP, dieFromUp);
            this.Items.Insert(DIE_FROMUPLEFT, dieFromUpLeft);
            this.Items.Insert(DIE_FROMUPRIGHT, dieFromUpRight);

            this.Index = DOWN_HIT;

            foreach (var item in this.Items)
            {
                item.MinimumIntervalIndexChange = 35;
            }
            this.Index = GO_UP;

            SoundAttack = SoundManager.Hero_Attack.CreateInstance();
            SoundDie = SoundManager.Hero_Die.CreateInstance();
            SoundBeAttacked = SoundManager.Hero_BeAttacked.CreateInstance();
        }

        public override List<Weapon> ReleasePowerAttack()
        {
            List<Weapon> weapons = null;
            if (!IsDying() && completePreparePowerRelease)
            {
                if (SoundAttack != null)
                    SoundAttack.Play();
                weapons = new List<Weapon>();
                for (int i = 0; i < Power; i++)
                {
                    var arch = new Arch(Content);
                    arch.Own = this;
                    arch.Power = ReleasePower();
                    arch.Direct = AttackTarget - this.Position;
                    arch.Position = this.Position;
                    weapons.Add(arch);
                }
                completePreparePowerRelease = false;
            }
            return weapons;
        }

        protected override void Paint(GameTime gameTime, SpriteBatch spriteBatch, object extraData)
        {
            Color color = Color.White;
            if (IsAttacking())
                color = powerColor;
            Current.Draw(gameTime, spriteBatch, color);
        }

        public static readonly Color powerColor = new Color(239, 93, 66, 255);


    }
}
